﻿package mortal.game.view.msgbroad
{
    import com.gengine.utils.*;
    import com.greensock.*;
    import flash.display.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.component.gconst.*;

    public class IssmNoticItem extends Sprite
    {
        private var _textField:TextField;
        private var _timerKey:int;
        private var _inTween:TweenMax;
        private var _outTween:TweenMax;
        private var _endFun:Function;

        public function IssmNoticItem()
        {
            mouseEnabled = false;
            mouseChildren = false;
            this._textField = new TextField();
            this._textField.selectable = false;
            this._textField.multiline = true;
            this._textField.wordWrap = true;
            this._textField.width = 500;
            this._textField.filters = [FilterConst.nameGlowFilter];
            var _loc_1:* = new GTextFormat("", 14, 16776960, true, null, null, null, null, TextFormatAlign.CENTER);
            this._textField.defaultTextFormat = _loc_1;
            this._textField.autoSize = TextFieldAutoSize.CENTER;
            addChild(this._textField);
            return;
        }// end function

        private function onInEnd() : void
        {
            this._timerKey = setTimeout(this.timerOutHandler, 60000);
            return;
        }// end function

        private function onOutEnd() : void
        {
            if (this._endFun != null)
            {
                this._endFun.call(this, this);
            }
            return;
        }// end function

        private function timerOutHandler() : void
        {
            this._outTween = TweenMax.to(this._textField, 0.3, {alpha:0, onComplete:this.onOutEnd});
            return;
        }// end function

        public function updateData(param1:String, param2:Function = null, param3:Boolean = true) : void
        {
            this._textField.htmlText = HTMLUtil.addColor(param1, "#ffff00");
            this._textField.height = this._textField.textHeight;
            if (param3)
            {
                this._textField.alpha = 0;
                this._textField.y = 20;
                this._inTween = TweenMax.to(this._textField, 0.3, {alpha:1, y:0, onComplete:this.onInEnd});
            }
            else
            {
                this._textField.alpha = 1;
                this._textField.y = 0;
                this.onInEnd();
            }
            return;
        }// end function

        public function killInEase() : void
        {
            if (this._inTween && this._inTween.active)
            {
                this._textField.y = 0;
                this._textField.alpha = 1;
                this._inTween.kill();
                this.onInEnd();
            }
            return;
        }// end function

        public function dispose() : void
        {
            this._endFun = null;
            clearTimeout(this._timerKey);
            if (this._inTween && this._inTween.active)
            {
                this._inTween.kill();
            }
            else if (this._outTween && this._outTween.active)
            {
                this._outTween.kill();
            }
            this._textField.alpha = 1;
            this._textField.y = 0;
            return;
        }// end function

        override public function get height() : Number
        {
            return this._textField.textHeight;
        }// end function

        override public function get width() : Number
        {
            return this._textField.width;
        }// end function

    }
}
